#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

//   QMenuBar* menuBar = new QMenuBar();
    QMenuBar* menuBar = this->menuBar();//如果QMenuBar存在，直接获取并返回，不存在，先创建新的在返回
   this->setMenuBar(menuBar);

   QMenu*menu =new QMenu("菜单");
   menu->setIcon(QIcon(":/open.png"));
   menuBar->addMenu(menu);

   QAction*actio1 = new QAction("菜单项1");
   actio1->setIcon(QIcon(":/open.png"));
   QAction*actio2 = new QAction("菜单项2");
   actio2->setIcon(QIcon(":/open1.png"));
   menu->addAction(actio1);
   menu->addAction(actio2);
}

MainWindow::~MainWindow()
{
    delete ui;
}

